package com.xxx.mall.config;

import cn.hutool.core.util.ArrayUtil;
import com.xxx.mall.adapter.AuthConfigAdapter;
import com.xxx.mall.filter.AuthFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;

/**
 * @author 邢晨旭
 * {@code @date} 2023/11/16
 */
@Configuration
public class AuthConfig {

    @Bean
    public FilterRegistrationBean<AuthFilter> filterRegistrationBean(AuthConfigAdapter authConfigAdapter, AuthFilter authFilter) {
        FilterRegistrationBean<AuthFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(authFilter);
        registrationBean.setName("authFilter");
        registrationBean.setOrder(0);
        registrationBean.setDispatcherTypes(DispatcherType.REQUEST);
        registrationBean.addUrlPatterns(ArrayUtil.toArray(authConfigAdapter.pathPatterns(), String.class));
        return registrationBean;
    }

}
